package view.GUI;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

/**
 *
 * @author Ben
 */
public class TabTitle extends JPanel implements ActionListener{
    private JButton btnClose;
    private JTabbedPane tabs;
    private JLabel lblTitle;

    public TabTitle(String title, JTabbedPane tabs, boolean showClose) {
       this.tabs = tabs;
       lblTitle = new JLabel(title);
       lblTitle.setBackground(Color.WHITE);
       this.setBackground(Color.WHITE);
       this.add(lblTitle);
       if(showClose){
           btnClose = new JButton("X");
           btnClose.setActionCommand("CLOSE");
           btnClose.addActionListener(this);
           this.add(btnClose);
       }
    }

    public void actionPerformed(ActionEvent ae) {
       if(ae.getActionCommand().equals("CLOSE")){
           int position= 0;
           while(position < tabs.getTabCount() && tabs.getTabComponentAt(position) != this){
                position++;
           }
           tabs.remove(position);
       }
    }

}
